package cn.edu.ctbu.myfirstweb.service.impl;

import cn.edu.ctbu.myfirstweb.dao.CourseRepository;
import cn.edu.ctbu.myfirstweb.dao.SCRepository;
import cn.edu.ctbu.myfirstweb.domain.Course;
import cn.edu.ctbu.myfirstweb.domain.SC;
import cn.edu.ctbu.myfirstweb.domain.SCID;
import cn.edu.ctbu.myfirstweb.service.SCService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SCImpService implements SCService {
    @Autowired
    SCRepository scRepository;

    @Autowired
    CourseRepository courseRepository;

    public Course getCourseByCid(Long cid){
        Course course = courseRepository.getCourseByCid(cid);
        return course;
    }

    public List<SC> finAll(){
        return scRepository.findAll();
    }

    public Page<SC> findAll(Pageable pageable){
        return scRepository.findAll(pageable);
    }

    public Page<SC> findAll(Example<SC> sc, Pageable pageable) {
        return scRepository.findAll(sc, pageable);
    }

    public SC insert(SC sc) {
        return scRepository.save(sc);
    }

    public SC update(SC sc) {
        return scRepository.save(sc);
    }

    public void delete(SCID scid) {
        scRepository.deleteById(scid);
    }

    public List<SC> queryByCID(Long cid) {
        return scRepository.getByCid(cid);
    }

    public SC getBySCID(SCID scid) {
        return scRepository.getByScid(scid);
    }


}
